﻿using System;
using System.Collections;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.VersionControl.Common;

namespace CodePlex.TeamFoundation.Adapters.VersionControl
{
  public interface IVersionControlServer
  {
    VersionControlArtifactProvider ArtifactProvider { get; }
    string AuthenticatedUser { get; }
    bool Canceled { get; set; }
    //static TraceSwitch ClientTracing { get; set; }
    string CurrentCommand { get; set; }
    //static int MaxBackgroundThreads { get; set; }
    //static int MaxResults { get; set; }
    Guid ServerGuid { get; }
    int SupportedFeatures { get; }
    TeamFoundationServer TeamFoundationServer { get; }

    event AfterWorkItemsUpdatedEventHandler AfterWorkItemsUpdated;
    event ProcessingChangeEventHandler BeforeCheckinPendingChange;
    event WorkspaceCancelEventHandler BeforeDeleteWorkspace;
    event ProcessingChangeEventHandler BeforeShelvePendingChange;
    event BeforeWorkItemsUpdateEventHandler BeforeWorkItemsUpdate;
    event CommitCheckinEventHandler CommitCheckin;
    event CommitShelvesetEventHandler CommitShelveset;
    event ConflictEventHandler Conflict;
    event WorkspaceEventHandler CreatedWorkspace;
    event DeletedShelvesetEventHandler DeletedShelveset;
    event WorkspaceEventHandler DeletedWorkspace;
    event DestroyedEventHandler Destroyed;
    event GettingEventHandler Getting;
    event MergeEventHandler Merging;
    event PendingChangeEventHandler NewPendingChange;
    event ExceptionEventHandler NonFatalError;
    event OperationEventHandler OperationFinished;
    event OperationEventHandler OperationStarting;
    event ResolvedConflictEventHandler ResolvedConflict;
    event PendingChangeEventHandler UndonePendingChange;
    event UnshelveShelvesetEventHandler UnshelveShelveset;
    event WorkspaceEventHandler UpdatedWorkspace;
    event WorkItemUpdatedEventHandler WorkItemUpdated;

    LabelResult[] CreateLabel(VersionControlLabel label, LabelItemSpec[] itemSpecs, LabelChildOption options);
    void CreateTeamProjectFolder(TeamProjectFolderOptions options);
    Workspace CreateWorkspace(string name);
    Workspace CreateWorkspace(string name, string owner);
    Workspace CreateWorkspace(string name, string owner, string comment);
    Workspace CreateWorkspace(string name, string owner, string comment, WorkingFolder[] mappings);
    Workspace CreateWorkspace(string name, string owner, string comment, WorkingFolder[] mappings, string computer);
    Workspace CreateWorkspace(string name, string owner, string comment, WorkingFolder[] mappings, string computer, bool fixMappingErrors);
    LabelResult[] DeleteLabel(string labelName, string labelScope);
    void DeleteShelveset(Shelveset shelveset);
    void DeleteShelveset(string shelvesetName, string shelvesetOwner);
    bool DeleteWorkspace(string workspaceName, string workspaceOwner);
    Item[] Destroy(ItemSpec itemSpec, VersionSpec versionSpec, VersionSpec stopAt, DestroyFlags flags);
    void DownloadFile(string serverPath, string localFileName);
    void DownloadFile(string serverPath, int deletionId, VersionSpec version, string localFileName);
    string[] GetAllCheckinNoteFieldNames();
    TeamProject[] GetAllTeamProjects(bool refresh);
    BranchHistoryTreeItem[][] GetBranchHistory(ItemSpec[] itemSpecs, VersionSpec version);
    Changeset GetChangeset(int changesetId);
    Changeset GetChangeset(int changesetId, bool includeChanges, bool includeDownloadInfo);
    CheckinNoteFieldDefinition[] GetCheckinNoteDefinitions(TeamProject[] teamProjects);
    CheckinNoteFieldDefinition[] GetCheckinNoteDefinitionsForServerPaths(string[] serverItems);
    PolicyEnvelope[] GetCheckinPoliciesForServerPaths(string[] serverItems);
    string[] GetEffectiveGlobalPermissions(string userName);
    string[] GetEffectivePermissions(string userName, string item);
    ExtendedItem[][] GetExtendedItems(ItemSpec[] itemSpecs, DeletedState deletedState, ItemType itemType);
    ExtendedItem[] GetExtendedItems(string path, DeletedState deletedState, ItemType itemType);
    FileType[] GetFileTypes();
    GlobalSecurity GetGlobalPermissions(string[] identityNames);
    Item GetItem(string path);
    Item GetItem(int itemId, int changesetNumber);
    Item GetItem(string path, VersionSpec version);
    Item GetItem(int itemId, int changesetNumber, bool includeDownloadInfo);
    Item GetItem(int itemId, int changesetNumber, GetItemsOptions options);
    Item GetItem(string path, VersionSpec version, int deletionId);
    Item GetItem(string path, VersionSpec version, int deletionId, bool includeDownloadInfo);
    Item GetItem(string path, VersionSpec version, int deletionId, GetItemsOptions options);
    ItemSet GetItems(string path);
    Item[] GetItems(int[] itemIds, int changesetNumber);
    ItemSet GetItems(string path, RecursionType recursion);
    Item[] GetItems(int[] itemIds, int changesetNumber, bool includeDownloadInfo);
    Item[] GetItems(int[] itemIds, int changesetNumber, GetItemsOptions options);
    ItemSet GetItems(string path, VersionSpec version, RecursionType recursion);
    ItemSet[] GetItems(ItemSpec[] itemSpecs, VersionSpec version, DeletedState deletedState, ItemType itemType);
    ItemSet GetItems(ItemSpec itemSpec, VersionSpec version, DeletedState deletedState, ItemType itemType, bool includeDownloadInfo);
    ItemSet GetItems(ItemSpec itemSpec, VersionSpec version, DeletedState deletedState, ItemType itemType, GetItemsOptions options);
    ItemSet[] GetItems(ItemSpec[] itemSpecs, VersionSpec version, DeletedState deletedState, ItemType itemType, bool includeDownloadInfo);
    ItemSet[] GetItems(ItemSpec[] itemSpecs, VersionSpec version, DeletedState deletedState, ItemType itemType, GetItemsOptions options);
    ItemSet GetItems(string path, VersionSpec version, RecursionType recursion, DeletedState deletedState, ItemType itemType);
    ItemSet GetItems(string path, VersionSpec version, RecursionType recursion, DeletedState deletedState, ItemType itemType, bool includeDownloadInfo);
    int GetLatestChangesetId();
    MergeCandidate[] GetMergeCandidates(ItemSpec source, string targetPath);
    MergeCandidate[] GetMergeCandidates(string sourcePath, string targetPath, RecursionType recursion);
    PendingChange GetPendingChange(int pendingChangeId);
    PendingChange GetPendingChange(int pendingChangeId, bool includeDownloadInfo);
    PendingChange[] GetPendingChanges(int[] pendingChangeIds);
    PendingChange[] GetPendingChanges(int[] pendingChangeIds, bool includeDownloadInfo);
    PendingSet[] GetPendingSets(string[] items, RecursionType recursion);
    ItemSecurity[] GetPermissions(string[] items, RecursionType recursion);
    ItemSecurity[] GetPermissions(string[] identityNames, string[] items, RecursionType recursion);
    TeamProject GetTeamProject(string name);
    TeamProject GetTeamProjectForServerPath(string serverPath);
    TeamProject[] GetTeamProjectsForServerPaths(string[] serverPaths);
    Workspace GetWorkspace(string localPath);
    Workspace GetWorkspace(WorkspaceInfo workspaceInfo);
    Workspace GetWorkspace(string workspaceName, string workspaceOwner);
    IEnumerable QueryHistory(string path, VersionSpec version, int deletionId, RecursionType recursion, string user, VersionSpec versionFrom, VersionSpec versionTo, int maxCount, bool includeChanges, bool slotMode);
    IEnumerable QueryHistory(string path, VersionSpec version, int deletionId, RecursionType recursion, string user, VersionSpec versionFrom, VersionSpec versionTo, int maxCount, bool includeChanges, bool slotMode, bool includeDownloadInfo);
    VersionControlLabel[] QueryLabels(string labelName, string labelScope, string owner, bool includeItems);
    VersionControlLabel[] QueryLabels(string labelName, string labelScope, string owner, bool includeItems, string filterItem, VersionSpec versionFilterItem);
    VersionControlLabel[] QueryLabels(string labelName, string labelScope, string owner, bool includeItems, string filterItem, VersionSpec versionFilterItem, bool includeDownloadInfo);
    ChangesetMerge[] QueryMerges(string sourcePath, VersionSpec sourceVersion, string targetPath, VersionSpec targetVersion, VersionSpec versionFrom, VersionSpec versionTo, RecursionType recursion);
    ChangesetMergeDetails QueryMergesWithDetails(string sourcePath, VersionSpec sourceVersion, int sourceDeletionId, string targetPath, VersionSpec targetVersion, int targetDeletionId, VersionSpec versionFrom, VersionSpec versionTo, RecursionType recursion);
    PendingSet[] QueryPendingSets(ItemSpec[] itemSpecs, string queryWorkspaceName, string queryUserName);
    PendingSet[] QueryPendingSets(ItemSpec[] itemSpecs, string queryWorkspaceName, string queryUserName, bool includeDownloadInfo);
    PendingSet[] QueryPendingSets(string[] items, RecursionType recursion, string queryWorkspaceName, string queryUserName);
    PendingSet[] QueryShelvedChanges(Shelveset shelveset);
    PendingSet[] QueryShelvedChanges(Shelveset shelveset, ItemSpec[] itemSpecs);
    PendingSet[] QueryShelvedChanges(string shelvesetName, string shelvesetOwner);
    PendingSet[] QueryShelvedChanges(string shelvesetName, string shelvesetOwner, ItemSpec[] itemSpecs);
    PendingSet[] QueryShelvedChanges(string shelvesetName, string shelvesetOwner, ItemSpec[] itemSpecs, bool includeDownloadInfo);
    Shelveset[] QueryShelvesets(string shelvesetName, string shelvesetOwner);
    Workspace[] QueryWorkspaces(string workspaceName, string workspaceOwner, string computer);
    void RenameCheckinNoteFieldName(string path, string oldName, string newName);
    bool ServerItemExists(string path, ItemType itemType);
    bool ServerItemExists(string path, VersionSpec version, DeletedState deletedState, ItemType itemType);
    void SetFileTypes(FileType[] fileTypes);
    PermissionChange[] SetGlobalPermissions(PermissionChange[] permissionChanges);
    SecurityChange[] SetPermissions(SecurityChange[] securityChanges);
    TeamProject TryGetTeamProject(string name);
    TeamProject TryGetTeamProjectForServerPath(string serverPath);
    Workspace TryGetWorkspace(string localPath);
    LabelResult[] UnlabelItem(string labelName, string labelScope, ItemSpec[] itemSpecs, VersionSpec version);
    void UpdateUserName();
  }
}
